#pragma once

#include<iostream>
#include<string>
#include<sys/types.h>
#include<sys/socket.h>
#include<cstring>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<stdlib.h>


class UdpClient{

private:
	int server_port; 
	int sockfd; 
	std::string server_ip;
public:
	UdpClient(std::string _ip, int _port):
		server_ip(_ip), server_port(_port)
	{}

	bool InitUdpClient()
	{
		sockfd = socket(AF_INET, SOCK_DGRAM, 0);
		if(sockfd < 0){
			std::cerr << "socket error" << std::endl;
			return false;
		}
		return true;
	}

	void Start()
	{
		struct sockaddr_in peer;
		memset(&peer,0,sizeof(peer));
		peer.sin_family = AF_INET;
		peer.sin_port = htons(server_port);
		peer.sin_addr.s_addr = inet_addr(server_ip.c_str());
		std::string msg;
		for(;;){
			std::cout << "please Enter ";
			std::cin >> msg;
			ssize_t write_size = sendto(sockfd,msg.c_str(),msg.size(),0,(struct sockaddr*)&peer,sizeof(peer));
		}		
	}
	
	~UdpClient(){}


};



